<template>
	<div class="container">
    <div style="position: relative;top: 270px">
      <router-link to="/index">
        <img src="../../assets/img/toNewsStyle.png" width="300px" height="150px">
      </router-link>
    </div>
	    <div class="login-form">
	      <div class="text"><img src="../../assets/img/loginLogo.png" width="230px" height="100px"></div>
	      <div class="form-item">
	        <input type="text" v-model="form.account" placeholder="邮箱">
	        <input type="password" v-model="form.password" placeholder="密码">
	      </div>
	      <div class="btn"  @click="userLogin()">登录</div>
        <div class="btn-back"><router-link to="/userPswUpdate">忘记密码！去找回</router-link></div>
	      <div class="other">
	        没有账号？<router-link to="/userreg">去注册</router-link>
	      </div>
	    </div>
	  </div>
</template>

<script>
	export default{
		data(){
			return{
				form:{
					account:"1503608495@qq.com",
					password:"11"
				}
			}
		},
		methods:{
      userLogin(){
        this.$http.post("userApi/UsersLoginCtl/login",this.form).then((resp)=>{
          if(resp.data.code==200){
            this.$message({
              showClose: true,
              message: '恭喜你，登录成功✔',
              type: 'success'
            });
            sessionStorage.setItem("userToken",resp.data.data.userToken);
            sessionStorage.setItem("name",resp.data.data.name);
            sessionStorage.setItem("imgUrl",resp.data.data.logo);
            if(this.id!=undefined){/*【是否在看新闻准备评论、点赞、收藏而触发的登录】*/
              this.$router.push({path:'/newsDetail',query:{id:this.id}});
            }else {
              this.$router.push("/userCenter");
            }
          }else if (resp.data.code==201){
            this.$message({
              showClose: true,
              message: resp.data.message,
              type: 'error'
            });
          }
        })
      }
		},mounted() {
		  this.id=this.$route.query.id;
    }
  }
</script>

<style src="../../assets/css/userlogin.css" scoped></style>
